package com.le.tester.javaThink.fifth.chapter18_Str;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * createTime：2021/8/13 15:29
 * description：Matcher 中的group
 */
public class Groups {
    public static final String POEM = "Twas brillig, and the slithy toves\n" +
            "Did gyre and gimble in the wabe.\n" +
            "All mimsy were the borogoves,\n" +
            "And the mome raths outgrabe.\n\n" +
            "Beware the Jabberwock, my son,\n" +
            "The jaws that bite, the claws that catch.\n" +
            "Beware the Jubjub bird, and shun\n" +
            "The frumious Bandersnatch.";

    public static void main(String[] args) {
        Matcher matcher = Pattern.compile("(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$").matcher(POEM);
        while (matcher.find()) {
            for (int j = 0; j <= matcher.groupCount(); j++) {
                System.out.print("[" + matcher.group(j) + "]");
                System.out.println();
            }
        }
    }
}
